import 'package:example/app/widget/fancy_fab.dart';
import 'package:flutter_base_framework/flutter_base_framework.dart';
import 'main_controller.dart';
import 'package:flutter/material.dart';

class MainPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<MainController>(
      initState: (_) {},
      builder: (logic) {
        return Scaffold(
          body: PageView(
            physics: NeverScrollableScrollPhysics(),
            children: logic.pages,
            controller: logic.pageController,
            onPageChanged: (index) => logic.index = index,
          ),
          bottomNavigationBar: BottomNavigationBar(
            items: [
              BottomNavigationBarItem(icon: Icon(Icons.home_filled), label: '首页'),
              BottomNavigationBarItem(icon: Icon(Icons.local_fire_department_outlined), label: '广场'),
              BottomNavigationBarItem(icon: Icon(Icons.android_sharp), label: '问答'),
              BottomNavigationBarItem(icon: Icon(Icons.foundation_outlined), label: '发现'),
              BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
            ],
            selectedItemColor: Colors.blueAccent,
            unselectedItemColor: Colors.grey,
            currentIndex: logic.index,
            onTap: (index) {
              logic.index = index;
              logic.pageController.jumpToPage(index);
            },
            type: BottomNavigationBarType.fixed,
          ),
          floatingActionButton: FancyFab(onPressed: (index) {
            switch(index){
              case 0:
                showToast('收藏站外文章');
                break;
              case 1:
                showToast('收藏网址');
                break;
              case 2:
                showToast('添加todo');
                break;
              case 3:
                showToast('分享文章');
                break;
              default:
                break;
            }
          },),
        );
      },
    );
  }
}
